from common.Utils import Utils

from tests.rypark_background.get_cookie import *


class Park:
    # 新建停车场
    def create(self, env, parkName, parkId):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/park/add"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        path = data_path + "park_create.json"
        dict = json.loads(Utils.parse(path, {"parkName": parkName, "parkId": parkId}))
        return requests.post(url, headers=headers, json=dict).json()

    # 获取停车场列表
    def list(self, env, parkName=None, parkTypes=None, status=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/park/list"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"parkName": parkName,
                "parkTypes": parkTypes,
                "status": status}
        return requests.post(url, headers=headers, json=dict).json()

    # 停车场编辑
    def update(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/park/edit"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        path = data_path + "park_update.json"
        dict = json.loads(Utils.parse(path, {"id": id}))
        return requests.post(url, headers=headers, json=dict).json()

    # 查看详情
    def detail(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/park/detail"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        return requests.get(url, headers=headers, params={"id": id}).json()

    # 启/停用停车场
    # status=状态（0：停用，1：启用）
    def change(self, env, id, status):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/park/parkStatusChange"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"id": id, "status": status}
        return requests.post(url, headers=headers, json=dict).json()
